@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private ClueRepository clueRepository;
    
    @Autowired
    private BusinessRepository businessRepository;
    
    @Autowired
    private ContractRepository contractRepository;
    
    @GetMapping("/getTodayInfo")
    public ResultDTO<Map<String, Object>> getTodayInfo() {
        Date today = new Date();
        Long userId = SecurityUtil.getCurrentUserId(); // 获取当前用户ID，可以根据具体情况进行修改
        
        // 获取今天处理的线索数量
        Long todayCluesNum = clueRepository.countByCreateUserIdAndCreateTimeBetween(userId, DateUtil.getStartTimeOfDate(today), DateUtil.getEndTimeOfDate(today));
        
        // 获取今天处理的商机数量
        Long todayBusinessNum = businessRepository.countByCreateUserIdAndCreateTimeBetween(userId, DateUtil.getStartTimeOfDate(today), DateUtil.getEndTimeOfDate(today));
        
        // 获取今天处理的合同数量
        Long todayContractNum = contractRepository.countByCreateUserIdAndCreateTimeBetween(userId, DateUtil.getStartTimeOfDate(today), DateUtil.getEndTimeOfDate(today));
        
        // 获取今天成交的合同金额
        BigDecimal todaySalesAmount = contractRepository.sumAmountByCreateUserIdAndCreateTimeBetween(userId, DateUtil.getStartTimeOfDate(today), DateUtil.getEndTimeOfDate(today));
        
        Map<String, Object> data = new HashMap<>();
        data.put("todayCluesNum", todayCluesNum);
        data.put("todayBusinessNum", todayBusinessNum);
        data.put("todayContractNum", todayContractNum);
        data.put("todaySalesAmount", todaySalesAmount);
        
        return ResultDTO.success(data);
    }
}